//
//  EditSettingCellData.m
//  18Birdies
//
//  Created by Lc on 15/4/30.
//  Copyright (c) 2015年 Lc. All rights reserved.
//

#import "EditSettingCell.h"
#import "EditSettingCellData.h"
#import "LcFoundation.h"

@implementation EditSettingCellData

+ (instancetype)cellDataWithTitle:(NSString*)title
                          content:(NSString*)content
                      placeholder:(NSString*)placeholder {
  LC_CHECK_NOT_EMPTY(title);
  EditSettingCellData* cellData = [[self alloc] init];
  cellData->_title = title.copy;
  cellData.content = content;
  cellData.contentEnabled = YES;
  cellData->_placeholder = placeholder.copy;
  cellData.clickable = NO;
  cellData.cellHeight = 44;
  return cellData;
}

- (Class)cellClazz {
  return EditSettingCell.class;
}

- (NSString*)nibName {
  return @"EditSettingCell";
}

- (void)refreshCell:(EditSettingCell*)cell {
  [super refreshCell:cell];
  cell.titleLabel.text = self.title;
  cell.textField.text = self.content;
  cell.textField.clearButtonMode = self.clearButtonMode;
  cell.textField.placeholder = nil;
  cell.placeHolderLabel.text = self.placeholder;
  [cell.placeHolderLabel setLcFont:[LcFont sgr17]];
  cell.placeHolderLabel.hidden = self.content.length > 0;
  if (self.contentNumeric) {
    cell.textField.keyboardType = UIKeyboardTypeNumberPad;
  } else {
    cell.textField.keyboardType = UIKeyboardTypeDefault;
  }
  cell.textField.textColor = LC_COLOR_DARK;
  cell.textField.secureTextEntry = self.contentPassword;
  cell.textField.enabled = self.contentEnabled;
  cell.arrowImageView.hidden = !self.showArrow;
  CGFloat rightMargin = self.contentEnabled ? 10 : 15;
  cell.textFieldRightMargin.constant = self.showArrow ? rightMargin + 18 : rightMargin;

  if (self.autoCapitalization) {
    cell.textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
  } else {
    cell.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
  }
}

@end
